package com.springapi.controller;

import com.springapi.entity.Goodsclass;
import com.springapi.service.GoodsclassService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类(Goodsclass)表控制层
 *
 * @author makejava
 * @since 2024-12-17 11:49:34
 */
@RestController
@RequestMapping("/api/goodsclass")
public class GoodsclassController {
    /**
     * 服务对象
     */
    @Resource
    private GoodsclassService goodsclassService;


    @GetMapping("/myfindAll")
    public List<Goodsclass> myfindAll(@RequestParam int appid, @RequestParam int shopid,@RequestParam String  level) {
        return goodsclassService.myfindAll(appid,shopid,level);
    }

    @GetMapping("/myfindclass")
    public List<Goodsclass> myfindclass(@RequestParam int appid, @RequestParam int shopid,@RequestParam int  fatherid) {
        return goodsclassService.myfindclass(appid,shopid,fatherid);
    }

    /**
     * 分页查询
     *
     * @param goodsclass 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Goodsclass>> queryByPage(Goodsclass goodsclass, PageRequest pageRequest) {
        return ResponseEntity.ok(this.goodsclassService.queryByPage(goodsclass, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Goodsclass> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.goodsclassService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param goodsclass 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Goodsclass> add(Goodsclass goodsclass) {
        return ResponseEntity.ok(this.goodsclassService.insert(goodsclass));
    }

    /**
     * 编辑数据
     *
     * @param goodsclass 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Goodsclass> edit(Goodsclass goodsclass) {
        return ResponseEntity.ok(this.goodsclassService.update(goodsclass));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.goodsclassService.deleteById(id));
    }

}

